//
//  ClipViewController.m
//  Core Graphics Code
//
//  Created by liboxiang on 2019/1/11.
//  Copyright © 2019 liboxiang. All rights reserved.
//

#import "ClipViewController.h"

@interface ClipViewController ()

@end

@implementation ClipViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIGraphicsBeginImageContext(self.view.bounds.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextAddEllipseInRect(context, CGRectMake(100, 100, 100, 100));
    CGContextClip(context);
    
    UIImage *clipImage = [UIImage imageNamed:@"clip.png"];
    [clipImage drawInRect:self.view.bounds];
    
    
    
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.layer.contents = (id)image.CGImage;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
